package com.wyg.epuser.utils;

import com.alibaba.fastjson.JSON;
import com.wyg.epcommonbase.common.util.file.StreamUtil;
import com.wyg.epuser.entity.EntityValidResp;
import lombok.SneakyThrows;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.InputStream;

/**
 * Description:
 *
 * @author WangYongGan
 * @since 2022/5/19 22:49
 */
public class HttpUtil {
    static String url = "localhost:5000/valid";

    @SneakyThrows
    public static EntityValidResp entityIsValid(String name) {
        CloseableHttpClient client = HttpClients.createDefault();

        url += "/" + name;
        HttpGet httpGet = new HttpGet(url);
        CloseableHttpResponse response = client.execute(httpGet);
        InputStream responseStream = response.getEntity().getContent();
        EntityValidResp entityTest = JSON.parseObject(StreamUtil.streamToString(responseStream), EntityValidResp.class);
        response.close();
        return entityTest;
    }
}
